package com.huawei.java.tools.csvreaders;

import java.io.BufferedReader;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.HashMap;

/**
 * @author henrydai
 * @version 1.0
 * @date 2022/3/15 19:33
 * @description
 */
public class QosReader {

    public void readFile(String dir, HashMap<String, Integer> qosMap)
    {
        //todo
        //System.out.println("进入qosreader");
        Path path = Paths.get(dir);
        try {
            BufferedReader br = Files.newBufferedReader(path);
            //读取第一行
            String s = br.readLine();
            String[] names = s.split(",");
            ArrayList<String> clientNames = new ArrayList<>();
            for(int i=0;i<names.length;i++)
            {
                clientNames.add(names[i]);
            }
            //从第二行开始读取, 记录 客户-边缘  qos
            //todo
            //System.out.println("开始处理第二行");
            s = br.readLine();
            while(s!=null)
            {
                //todo
                //System.out.println("开始处理-->"+s);
                String[] edgeAndQos = s.split(",");
                String edgeName = edgeAndQos[0];
                for(int i=1;i<edgeAndQos.length;i++)
                {
                    String name = clientNames.get(i)+"_"+edgeName;
                    qosMap.put(name, Integer.parseInt(edgeAndQos[i]));
                }
                s= br.readLine();
            }
            br.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
